package com.ws.q1.controller;


import com.ws.q1.bean.LanMu;
import com.ws.q1.bean.XianLu;
import com.ws.q1.bean.YouQingLianJie;
import com.ws.q1.service.LanMuService;
import com.ws.q1.service.XianLuService;
import com.ws.q1.service.YouQingLianJieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/qiantai")
public class ActionController {
    @Autowired
    private LanMuService lanmuService;
    @Autowired
    private YouQingLianJieService youQingLianJieService;
    @Autowired
    private XianLuService xianLuService;
    @RequestMapping("/index")
    public String index(Model model) throws SQLException {
        // 获取所有栏目数据
        List<LanMu> list1 = lanmuService.list1();
        for (LanMu user : list1) {
            System.out.println(user);
        }
        model.addAttribute("list1", list1);

        // 获取所有轮播图数据 判断 lunbo字段是否是1 如果是1 就放到lun里面
        List<XianLu> lunbo = xianLuService.list();
        List<XianLu> lun = new ArrayList<>();
        for (XianLu xl : lunbo) {
            if (xl.getLunbo()==1) {
                lun.add(xl);
            }
        }
        model.addAttribute("lun", lun);



        // 获取所有线路数据
        List<XianLu> xianlu = xianLuService.list();
        for (XianLu xianLu : xianlu) {
            System.out.println(xianLu);
        }
        model.addAttribute("xianlu", xianlu);
        model.addAttribute("lun", lun);


        // 获取所有友情链接数据
        List<YouQingLianJie> list = youQingLianJieService.list();
        for (YouQingLianJie you : list) {
            System.out.println(you);
        }
        model.addAttribute("you", list);
        return "qiantai/index";



    }

    @RequestMapping("/login")
    public String login(){
        return "denglu/login";//登录
    }

    @RequestMapping("/register")
    public String register(){
        return "denglu/register";//注册
    }

    @RequestMapping("routedetail")
    public String xianlu(){
        return "qiantai/route_detail";//详情页
    }


    @RequestMapping("routelist")
    public String routelist(){
        return "qiantai/route_list";//搜索
    }

    @RequestMapping("gerenxinxi")
    public String myorder(){
        return "qiantai/gerenxinxi";//个人信息
    }

    @RequestMapping("myfavorite")
    public String myfavorite(){
        return "qiantai/myfavorite";//我的收藏
    }











}
